package xixirupan.tmgp.tencent.com.vmeim;

import android.app.Activity;
import android.content.Context;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;

import android.util.Log;
import android.view.View;
import android.widget.FrameLayout;
import android.widget.RadioButton;

import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.Unbinder;
import xixirupan.tmgp.tencent.com.vmeim.base.BaseActivity;
import xixirupan.tmgp.tencent.com.vmeim.model.FragmentFactory;
import xixirupan.tmgp.tencent.com.vmeim.model.IGetFragments;
import xixirupan.tmgp.tencent.com.vmeim.presenter.GetFragmentsPresenter;
import xixirupan.tmgp.tencent.com.vmeim.view.IGetViewData;

public class MainActivity extends BaseActivity  {
    @BindView(R.id.frameLayout_main)
    FrameLayout frameLayoutMain;
    @BindView(R.id.house_main)
    RadioButton houseMain;
    @BindView(R.id.discover_main)
    RadioButton discoverMain;
    @BindView(R.id.quan_main)
    RadioButton quanMain;
    @BindView(R.id.shopcar_main)
    RadioButton shopcarMain;
    @BindView(R.id.me_main)
    RadioButton meMain;
    private Unbinder bind;
    //按钮对应的所有fragment集合
    private List<Fragment> lists;

    //目前fragment的下标
    private  int currentIndex =0;
    //
    private GetFragmentsPresenter presenter;

    private Context context;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        bind = ButterKnife.bind(this);

       context =this;
        final FragmentManager manager = getSupportFragmentManager();
        presenter =new GetFragmentsPresenter(new FragmentFactory(), new IGetViewData() {
            @Override
            public FragmentManager getManager() {
                return manager;
            }
        },currentIndex);
        presenter.setInitView();
    }
    //radiobutton的点击事件
    public void clickView(View view) {
        switch (view.getId())
        {
            //美购
            case R.id.house_main:

                presenter.switchFragment(0);
                 currentIndex =0;

                break;
            //发现
            case R.id.discover_main:
                presenter.switchFragment(1);
                currentIndex =1;
                break;
            //美圈
            case R.id.quan_main:
                presenter.switchFragment(2);
                 currentIndex =2;
                break;
            //购物车
            case R.id.shopcar_main:
                presenter.switchFragment(3);
                 currentIndex =3;
                break;
            //我的
            case R.id.me_main:
               presenter.switchFragment(4);
                 currentIndex =4;
                break;
        }
    }


    @Override
    protected void onDestroy() {
        super.onDestroy();
        bind.unbind();
    }

}
